package cn.jingzhuan.fm.ui.epoxy.model

import android.support.v7.widget.LinearLayoutManager
import android.view.View
import android.view.ViewGroup
import cn.jingzhuan.fm.R
import cn.jingzhuan.fm.databinding.ItemFmTodayListenBinding
import cn.jingzhuan.fm.databinding.ViewFmTodayListenBinding
import cn.jingzhuan.fm.pojo.AlbumTodayListen
import cn.jingzhuan.fm.ui.adapter.BaseBindingRecyclerAdapter
import cn.jingzhuan.fm.ui.adapter.BindingRecyclerViewHolder
import cn.jingzhuan.fm.ui.decoration.HorizontalSpacesItemDecoration
import cn.jingzhuan.fm.ui.transformation.RoundedCornersTransformation
import cn.jingzhuan.fm.utils.DisplayUtils
import cn.jingzhuan.fm.utils.ImageLoader
import com.airbnb.epoxy.DataBindingEpoxyModel
import com.airbnb.epoxy.EpoxyModelClass


@EpoxyModelClass(layout = R.layout.view_fm_today_listen)
abstract class FMIndexTodayListenModel : DataBindingEpoxyModel(){

    var todayListenList : MutableList<AlbumTodayListen> = mutableListOf()

    override fun buildView(parent: ViewGroup): View {
        var view = super.buildView(parent)
        var binding = view.tag as ViewFmTodayListenBinding
        val decoration = HorizontalSpacesItemDecoration(DisplayUtils.dip2px(parent.context,15f))
        var adapter = object : BaseBindingRecyclerAdapter<AlbumTodayListen>(parent.context,todayListenList) {
            override fun getItemLayoutId(viewType: Int): Int = R.layout.item_fm_today_listen

            override fun bindData(holder: BindingRecyclerViewHolder, position: Int, item: AlbumTodayListen) {
                var itembinding =  holder.binding as ItemFmTodayListenBinding
                itembinding.todayListen = item
                ImageLoader.loadImage(itembinding.audioImage,item.albumLogoUrl, RoundedCornersTransformation(parent.context,DisplayUtils.dip2px(parent.context,4f),0,RoundedCornersTransformation.CornerType.TOP))
            }

        }
        var linearLayoutManager = LinearLayoutManager(parent.context)
        linearLayoutManager.orientation = LinearLayoutManager.HORIZONTAL
        binding.recyclerView.layoutManager  = linearLayoutManager
        binding.recyclerView.adapter = adapter
        binding.recyclerView.addItemDecoration(decoration)

        return view
    }
}